//UMASS Lowell
//SW Engineering
//Spring 2010
//Project: BUFDB - Setup component
//Version: 1
//Author: Chuck DeLoid
//Date: 3/31/10
//Purpose: A C++ program that uses the SQL API to connect to a postgreSQL database 
//			server and create a database, a table, and fill it with one record,
//			display all records (1) in the table, then disconnect from the database
//
// STATUS: when compiling using command C:\MinGW>mingw32-c++.exe db_connect.cpp -I MinGW
// I am no longer having problems with the include files, but just compile
// errors. For some reason I can't connect to PosgresQL server with the windows
// app (PG Admin III) which is how I was going to verify that things were being
// created. I'll worry about that later. First, I need to get this compiled.

#include <iostream>
using namespace std;

#include <stdio.h>  
#include <SQLAPI.h> // main SQLAPI++ header


int main(int argc, char* argv[])
{
	//*************************************************************************
	//							CONNECT TO POSTGRESQL 
	//*************************************************************************
	/* Create SAconnection object con */
	SAConnection con;
	
	/*Set Client of Object con to PostgreSQL */
	con.setClient(SA_PostgreSQL_Client);

	/* Get Client Command to ensure PostgreSQL was assigned as client*/
	con.Client();

	/* Open database connection */
	con.Connect("localhost@", "postgres", "Kollsman1", SA_PostgreSQL_Client);

	/* Check the status of the database */
	//if (con.isConnected())
	cout<<"good to go"<< endl;
	
	//*************************************************************************
	//							CREATE DATABASE AND TABLES
	//*************************************************************************

	/* make command object generate a SQL command for create database called test*/
	//SACommand cmd_db(&con);
	//cmd_db.setCommandText("CREATE DATABASE steptwo", SA_CmdSQLStmt);
	
	/* Execute cmd_db command */
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//cmd_db.Execute();

	/* make command object generate a SQL command for create table called weather*/
	/* Also create 4 columns to store data at a later date */
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//SACommand cmd_tbl(&con);
	//cmd_tbl.setCommandText(
     //   "CREATE TABLE weather(ID int, city varchar(80), temp_lo int, temp_hi int, prcp real, date date);", 
      //  SA_CmdSQLStmt);

	/* Execute cmd_tbl command */
	//cmd_tbl.Execute();							
	
	//*************************************************************************
	//							INSERT DATA
	//*************************************************************************


	/* Insert data into the table weather */
	//SACommand cmd_data(&con);
	//cmd_data.setCommandText(
    //    "INSERT into weather(ID, city, temp_lo, temp_hi, prcp, date) values(1, 'Boston', 25, 25, 123456, '02/19/55)", 
    //    SA_CmdSQLStmt);
	
	/* Execute cmd_data command */
    //cout << __FILE__ << ":" << __LINE__ << endl;
    // Throws exception
	//cmd_data.Execute();
	
	//*************************************************************************
	//							FETCH
	//***********************************************************************

	/* Fetch data from weather table and generate report - values from table should */
	/* be output to the command line */
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//SACommand cmd_get(&con);
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//cmd_get.setCommandText("SELECT * FROM weather", SA_CmdSQLStmt);
	
	/* Execute cmd_get command */
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//cmd_get.Execute();

	
	
	
	//*************************************************************************
	//							DISCONNECT FROM POSTGRESQL
	//*************************************************************************
		
	/* Disconnect from the database */
    //cout << __FILE__ << ":" << __LINE__ << endl;
	//con.Disconnect();

	
		
	return 0;
	
}




